package com.ruoyi.quartz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.quartz.domain.SysJobInfoConfig;
import com.ruoyi.quartz.mapper.SysJobInfoConfigMapper;
import com.ruoyi.quartz.service.ISysJobInfoConfigService;
import com.ruoyi.quartz.util.CronUtils;

/**
 * job配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-05-01
 */
@Service
public class SysJobInfoConfigServiceImpl implements ISysJobInfoConfigService 
{
    @Autowired
    private SysJobInfoConfigMapper sysJobInfoConfigMapper;

    /**
     * 查询job配置
     * 
     * @param id job配置主键
     * @return job配置
     */
    @Override
    public SysJobInfoConfig selectSysJobInfoConfigById(Long id)
    {
        return sysJobInfoConfigMapper.selectSysJobInfoConfigById(id);
    }

    /**
     * 查询job配置列表
     * 
     * @param sysJobInfoConfig job配置
     * @return job配置
     */
    @Override
    public List<SysJobInfoConfig> selectSysJobInfoConfigList(SysJobInfoConfig sysJobInfoConfig)
    {
        return sysJobInfoConfigMapper.selectSysJobInfoConfigList(sysJobInfoConfig);
    }

    /**
     * 新增job配置
     * 
     * @param sysJobInfoConfig job配置
     * @return 结果
     */
    @Override
    public int insertSysJobInfoConfig(SysJobInfoConfig sysJobInfoConfig)
    {
        return sysJobInfoConfigMapper.insertSysJobInfoConfig(sysJobInfoConfig);
    }

    /**
     * 修改job配置
     * 
     * @param sysJobInfoConfig job配置
     * @return 结果
     */
    @Override
    public int updateSysJobInfoConfig(SysJobInfoConfig sysJobInfoConfig)
    {
        return sysJobInfoConfigMapper.updateSysJobInfoConfig(sysJobInfoConfig);
    }

    /**
     * 批量删除job配置
     * 
     * @param ids 需要删除的job配置主键
     * @return 结果
     */
    @Override
    public int deleteSysJobInfoConfigByIds(String ids)
    {
        return sysJobInfoConfigMapper.deleteSysJobInfoConfigByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除job配置信息
     * 
     * @param id job配置主键
     * @return 结果
     */
    @Override
    public int deleteSysJobInfoConfigById(Long id)
    {
        return sysJobInfoConfigMapper.deleteSysJobInfoConfigById(id);
    }

    /**
     * 校验cron表达式是否有效
     * 
     * @param cronExpression 表达式
     * @return 结果
     */
    @Override
    public boolean checkCronExpressionIsValid(String cronExpression)
    {
        return CronUtils.isValid(cronExpression);
    }

	@Override
	public boolean run(SysJobInfoConfig job) {
		return sysJobInfoConfigMapper.updateSysJobInfoConfig(job)==1?true:false;
	}
}
